'''
Created on May 15, 2012

@author: TANDA
'''

class TestCase(object):
    '''
    classdocs
    '''
    
    
    def __init__(self, values, output):
        '''
        Constructor
        '''
        self.values = values
        self.output = output
        

    def getValues(self):
        return self.values
    
    def getOutput(self):
        return self.output

class Test(object):
    '''
    classdocs
    '''


    def __init__(self, line_to_test, id_number, params):
        '''
        Constructor
        '''
        self.id_number = id_number;
        self.line_to_test = line_to_test;
        self.params = params;
        self.test_cases = [];
        
    def get_id(self):
        return self.id_number
    
    def add_test_case(self, params_input_value, output):
        self.test_cases.append(TestCase(params_input_value, output))
        
    def setup_test(self, params_input_value):
        vars_dict = {}
        for param, value in zip(self.params, params_input_value):
            vars_dict[param] = value
            
        return vars_dict
        
    def run_tests(self):
        tests_result = []
        for test_case in self.test_cases:
            vars_dict = self.setup_test(test_case.getValues())
            
            output = eval(self.line_to_test, vars_dict)

            if (output == test_case.getOutput()):
                tests_result.append('Success on ' + str(test_case.getValues()) + ', output was ' + str(output) + ' as expected.')
            else:
                tests_result.append('Fail on input ' + str(test_case.getValues()) + ': Result was ' + str(output) + ' but expected ' + str(test_case.getOutput()) + '.')
                
        return tests_result
        
